﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Reflection;
using Axial.Reflection;
using System.Web.UI;

namespace Axial
{
	public class WFScriptButton : Button
	{
		public string MethodName { get; set; }

		protected override void OnLoad(EventArgs e)
		{
			this.Controls.Add(new WFScript { MethodName = MethodName });

			base.OnLoad(e);
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);

			OnClientClick = OnClientClick + "; " + MethodName + "(); return false;";
		}

		/*
		protected override void Render(System.Web.UI.HtmlTextWriter writer)
		{
			base.Render(writer);

			MethodInfo method = Page.GetMethod(MethodName);
			if (method == null)
				throw new Exception("Method " + MethodName + " not found in the page");
			writer.WriteBeginTag("script");
			writer.WriteAttribute("type", "text/javascript");
			writer.Write(HtmlTextWriter.TagRightChar);

			JSWriter codeWriter = new JSWriter();
			codeWriter.AddPrivateFunction(MethodName, 1, JSWebTranslator.DissembleMethod(method, Page));
			writer.Write(codeWriter.ToString());
	
			writer.WriteEndTag("script");
			writer.WriteLine();
		}
		*/
	}
}
